package example.step2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ReferenceSerial2 {

    public static void main(String[] args) throws Exception {

        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("E:\\idea-workspace\\gitee\\demo\\serializable\\src\\main\\java\\objfile\\ref2.obj"));
        Integer first = new Integer("1");
        Integer second = Integer.valueOf("2");
        out.writeObject(new Integer("3"));
        out.writeObject(first);
        out.writeObject(new Integer("4"));
        out.writeObject(second);
        out.writeObject(first);
        out.writeObject(second);
        out.close();

        ObjectInputStream in = new ObjectInputStream(new FileInputStream("E:\\idea-workspace\\gitee\\demo\\serializable\\src\\main\\java\\objfile\\ref2.obj"));

        Integer a1 = (Integer)in.readObject();
        Integer a2 = (Integer)in.readObject();
        Integer a3 = (Integer)in.readObject();
        Integer a4 = (Integer)in.readObject();
        Integer a5 = (Integer)in.readObject();
        Integer a6 = (Integer)in.readObject();

        System.out.println(a1);
        System.out.println(a2);
        System.out.println(a3);
        System.out.println(a4);
        System.out.println(a5);
        System.out.println(a6);

        in.close();

    }
}